Elisp: Positions
Table of Contents
A position is the index between 2 characters or before the 1st character in the text of a buffer. It starts from 1 (which is before the 1st characer). Positions can also be represented by markers, special objects that relocate automatically when text is inserted or deleted.
1. Point
Commands move point through texts to allow editing and insertion at different places.
Each buffer has its own value point, which is independent of points in other buffers.
Each window also have a value of point, which is independent of the value of points in other windows on the same buffer.
point- Returns the value of point in the current buffer
point-min- Returns the minimum accessible value of point in the current buffer.
point-max- Returns the maximum accessible value of point.
buffer-end FLAG- Returns
point-maxifflagis greater than 0,point-minotherwise. buffer-size &optional BUFFER- Returns total number of characters of the
buffer(current buffer by default).
2. Motion
Motion functions change the value of point.
2.1. Motion by Characters
goto-char POSITIONSets point in the current buffer to
POSITION. If narrowing,POSITIONstill counts from the beginning of buffer, but the point cannot go outside the accessible portion and will go to the beginning or end of accessible portion.When this function is called interactively,
POSITIONis the numeric prefix argument if provided; otherwise it’s read from minibuffer.This function returns
POSITION.forward-char &optional COUNTThis function moves point
COUNTpositions forward (towards the end of buffer; or backward, ifCOUNTis negative). IfCOUNTisnil, it’s 1 by default.Attempting to move past the beginning or end will raise an error symbol:
beginning-of-bufferorend-of-buffer.In an interactive call,
COUNTis the numeric prefix argument.backward-char &optional COUNT- Almost same as
forward-char, but opposite direction.
2.2. Motion by Words
forward-word &optional COUNTbackward-word &optional COUNTwords-include-escapesinhibit-field-text-motionfind-word-boundary-function-tableforward-word-strictly &optional COUNTbackward-word-strictly &optional COUNT